'use strict';

angular.module('snPaas_om').service('appStore',['$http','$q','baseUrl','$timeout',function($http,$q,baseUrl,$timeout){
	var start = function(deployId,appId){
		var deferred = $q.defer();
		$http.get(baseUrl.ajax+'/rest/app/start',{params:{appId:appId,deployId:deployId}}).success(function(data, status, headers, config){
			deferred.resolve(data);
		}).error(function(){
			deferred.reject();
		});
		return deferred.promise;
	};
	var stop = function(deployId,appId){
		var deferred = $q.defer();
		$http.get(baseUrl.ajax+'/rest/app/stop',{params:{appId:appId,deployId:deployId}}).success(function(data, status, headers, config){
			deferred.resolve(data);
		}).error(function(){
			deferred.reject();
		});
		return deferred.promise;
	};
	var restart = function(deployId,appId){
		var deferred = $q.defer();
		$http.get(baseUrl.ajax+'/rest/app/restart',{params:{appId:appId,deployId:deployId}}).success(function(data, status, headers, config){
			deferred.resolve(data);
		}).error(function(){
			deferred.reject();
		});
		return deferred.promise;
	};
	return {
		'start':start,
		'stop':stop,
		'restart':restart
	};
}]);